#!/bin/bash

source /etc/profile

if [ -n "$1" ] ;then
  do_date=$1
else
  do_date=`date -d "-1 day" +%F`
fi


sql="
insert overwrite table ads.ads_member_active_count
partition(dt='$do_date')
select daycnt, weekcnt, monthcnt
from (select dt, count(*) daycnt
      from dws.dws_member_start_day
      where dt='$do_date'
      group by dt
      ) day
join
      (select dt, count(*) weekcnt
      from dws.dws_member_start_week
      where dt='$do_date'
      group by dt
      ) week on day.dt=week.dt
join
      (select dt, count(*) monthcnt
      from dws.dws_member_start_month
      where dt='$do_date'
      group by dt
      ) month on day.dt=month.dt;
"

hive -e "$sql"